package com.java2207.group1.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.java2207.group1.bo.CasesBo;
import com.java2207.group1.pojo.Cases;
import com.java2207.group1.service.CasesService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * Lenovo 2022/7/26 17:14
 *
 * 读取web文件的监听器
 */
@Component
@Scope("prototype")    //设置成多例模式
public class CasesConsultListener extends AnalysisEventListener<CasesBo> {

    @Autowired
     CasesService casesService;

    @Override
    public void invoke(CasesBo data, AnalysisContext analysisContext) {

        System.out.println(data);
        Cases cas = new Cases();

        //属性拷贝  将data的属性值复制给case
        BeanUtils.copyProperties(data,cas);
        casesService.addCase(cas);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
